package com.whiteape.book.ui.adapter;


import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.model.bo.CategoryDetailBo;
import com.whiteape.book.utils.StringUtils;

import java.util.List;

import static com.umeng.socialize.utils.ContextUtil.getContext;

/**
 * Created by newbiechen on 17-6-2.
 */

public class SourceCategoryAdapter extends BaseQuickAdapter<CategoryDetailBo, BaseViewHolder> {
//    @Override
//    protected IViewHolder<CategoryDetailBo> createViewHolder(int viewType) {
//        return new SourceCategoryHolder();
//    }


    public SourceCategoryAdapter(int layoutResId, @Nullable List<CategoryDetailBo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CategoryDetailBo item) {
        //显示图片
//        mIvCover = findById(R.id.search_book_iv_cover);
//        mTvName = findById(R.id.search_book_tv_name);
//        mTvAuthor = findById(R.id.search_book_tv_author);
//        mTvSource = findById(R.id.search_book_tv_source);
//        mTvDesc = findById(R.id.search_book_tv_desc);
        Glide.with(getContext())
                .load(item.getCoverUrl())
                .placeholder(R.mipmap.no_cover_portrait)
//                .error(R.mipmap.ic_load_error)
                .into((ImageView) helper.getView(R.id.category_iv_cover));

        helper.setText(R.id.category_tv_name, item.getTitle());
        if (!item.getAuthor().isEmpty()) {
            helper.setText(R.id.category_tv_author, "作者：" + item.getAuthor());
        } else {
            if (!item.getState().isEmpty()) {

                helper.setText(R.id.category_tv_author, "状态：" + item.getState());
            } else {
                if (!item.getCategory().isEmpty()) {
                    helper.setText(R.id.category_tv_author, item.getCategory());
                }
            }
        }

        if (!StringUtils.isEmpty(item.getLastChapter())) {
            helper.setText(R.id.category_tv_last_chapter, "最新章节：" + item.getLastChapter());
        } else {
            if (!StringUtils.isEmpty(item.getDesc())) {

                helper.setText(R.id.category_tv_last_updated, "简介：" + item.getDesc());
            }
        }
        if (!StringUtils.isEmpty(item.getLastUpdated())) {

            helper.setText(R.id.category_tv_last_updated, "最后更新：" + item.getLastUpdated());
        } else {
            if (!StringUtils.isEmpty(item.getCategory())) {

                helper.setText(R.id.category_tv_last_chapter, "分类：" + item.getCategory());
            }
        }

//        mTvSource.setText("网源：" + data.getSiteSourceBean().getSiteName());
//        mTvDesc.setText(data.getDesc());

    }
}
